// createRouter: 创建router实例对象
// createWebHistory: 创建history模式的路由
import { createRouter, createWebHistory } from 'vue-router'

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  // path和component对应关系的位置
  routes: [
    {
      //布局架子
      path: '/',
      component: () => import('@/views/Layout/index.vue'),
      // 子路由路径不需 /开头！！！否则会出问题
      children: [
        {
          //首页
          path: '', //默认二级路由
          component: () => import('@/views/Home/index.vue'),
        },
        {
          // 分类
          path: 'category/:id',
          component: () => import('@/views/Category/index.vue'),
        },
        {
          // 二级分类
          path: 'category/sub/:id',
          component: () => import('@/views/SubCategory/index.vue'),
        },
        {
          // 商品详情
          path: 'detail/:id',
          component: () => import('@/views/Detail/index.vue'),
        },
        {
          // 购物车列表
          path: 'cartlist',
          component: () => import('@/views/CartList/index.vue'),
        },
        {
          // 订单结算页
          path: 'checkout',
          component: () => import('@/views/CheckOut/index.vue'),
        },
        {
          // 订单支付页
          path: 'pay/:id',
          component: () => import('@/views/Pay/index.vue'),
        },
        {
          // 订单成功页
          path: 'paycallback',
          component: () => import('@/views/PayBack/index.vue'),
        },
        {
          // 会员中心
          path: 'member',
          component: () => import('@/views/Member/index.vue'),
          redirect: 'member/user',
          children: [
            {
              // 用户信息
              path: 'user',
              component: () => import('@/views/Member/components/UserInfo.vue'),
            },
            {
              // 订单中心
              path: 'order',
              component: () => import('@/views/Member/components/UserOrder.vue'),
            },
          ],
        },
      ],
    },
    {
      //登录页
      path: '/login',
      component: () => import('@/views/Login/index.vue'),
    },
  ],
  // 路由滚动行为
  scrollBehavior() {
    return {
      top: 0,
    }
  },
})

export default router
